package com.study.excel.easyexcel;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;
import com.study.excel.easyexcel.dto.ConverterData;
import com.study.excel.easyexcel.dto.DemoData;
import com.study.excel.easyexcel.dto.IndexOrNameData;
import com.study.excel.easyexcel.listener.ConverterDataListener;
import com.study.excel.easyexcel.listener.IndexOrNameListener;
import org.junit.jupiter.api.Test;

public class EasyExcelTest {

    private String path = "D:\\Users\\门博\\IdeaProjects\\study\\demo.xlsx";

    /**最简单的读取 **/
    @Test
    public void testReadFile(){
        EasyExcel.read(path,DemoData.class,new PageReadListener<DemoData>(dataList->{
           for (DemoData demoData : dataList) {
               System.out.println(demoData);
           }
        })).sheet().doRead();
    }

    @Test
    public void readByName(){
        /**默认读取第一个 **/
        EasyExcel.read(path, IndexOrNameData.class,new IndexOrNameListener()).sheet().doRead();
    }


    @Test
    public void repeateRead(){
        /** 读取所有sheet文件**/
        EasyExcel.read(path, IndexOrNameData.class,new IndexOrNameListener()).doReadAll();
    }


    @Test
    public void convertRead(){
        EasyExcel.read(path, ConverterData.class,new ConverterDataListener()).sheet().doRead();
    }
}
